<%@ page language="java" import="java.util.List" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
	<head>
		<title>
			<logic:present name="group" scope="session">
				<bean:write name="group" scope="session"/>
			</logic:present>
			<logic:notPresent name="group" scope="session">Welcome</logic:notPresent>
		</title>
		<link href="form/main.css" rel="stylesheet" type="text/css">
	</head>
	<body>
		<logic:notPresent name="groups" scope="session">
			<logic:redirect page="/illegal_access.jsp"></logic:redirect>
		</logic:notPresent>
		<logic:notPresent name="topics" scope="session">
			<logic:redirect page="/illegal_access.jsp"></logic:redirect>
		</logic:notPresent>
		<logic:present name="userid" scope="session">
			<logic:notPresent name="name" scope="request">
				<logic:redirect page="/illegal_access.jsp"></logic:redirect>
			</logic:notPresent>
			<logic:notPresent name="grade" scope="request">
				<logic:redirect page="/illegal_access.jsp"></logic:redirect>
			</logic:notPresent>
		</logic:present>
		<logic:notPresent name="page" scope="session">
			<logic:redirect page="/illegal_access.jsp"></logic:redirect>
		</logic:notPresent>
		<% 
			int current_offset=(Integer) session.getAttribute("page");
			int list_size=((List) session.getAttribute("topics")).size();
			int current_end=current_offset+10;
			pageContext.setAttribute("co", current_offset);
		 %>
		<div class="container">
			<div class="header">
				<html:img page="/yssz.jpg"/>
                <div id="login">
					<logic:present name="group" scope="session">
						<html:link action="clear">Welcome Page</html:link>&nbsp;
					</logic:present>
					<html:link action="viewWord"><logic:present name="admin" scope="session">organize </logic:present>sensitive words</html:link>
					<html:link page="/form/search.jsp">search engine</html:link>
					<logic:notPresent name="admin" scope="session">
							<html:link action="encyclopedia">encyclopedia</html:link>
						</logic:notPresent>
				</div>
			</div>
			<div class="sidebar1">
				<ul class="nav">
					<logic:iterate id="groupList" name="groups" scope="session">
						<bean:define id="groupName" name="groupList" property="name"></bean:define>
						<li><a href="/se3/mainPre.do?group=<%=groupName %>"><bean:write name="groupName"/></a></li>
					</logic:iterate>
				</ul>
				<logic:present name="admin" scope="session">
					<ul class="nav">
						<li><html:link page="/form/addGroup.jsp">+add group</html:link></li>
					</ul>
				</logic:present>
			</div>
			<div class="content">
				<table width="650px" border="1" cellspacing="0" cellpadding="0">
					<tr align="center" valign="middle">
						<td>话题</td>
						<td>话题组</td>
						<td>发布者</td>
						<td>发布日期</td>
						<td>最后回复者</td>
						<td>回复 日期</td>
						<logic:present name="admin" scope="session">
							<td>&nbsp;</td>
						</logic:present>
					</tr>
					<logic:iterate id="topicList" name="topics" scope="session" length="10" offset="co">
						<tr align="center" valign="middle">
							<bean:define id="topic_id" name="topicList" property="id"></bean:define>
							<bean:define id="topic_group" name="topicList" property="group"></bean:define>
							<td><a href="/se3/prePoster.do?topicid=<%=topic_id %>"><bean:write name="topicList" property="name"/></a></td>
							<td><a href="/se3/mainPre.do?group=<%=topic_group %>"><bean:write name="topicList" property="group"/></a></td>
							<td><bean:write name="topicList" property="topic_creater"/></td>
							<td><bean:write name="topicList" property="topic_create_time"/></td>
							<td><bean:write name="topicList" property="poster_creater"/></td>
							<td><bean:write name="topicList" property="poster_create_time"/></td>
							<logic:present name="admin" scope="session">
								<td><a href="/se3/deleteTopic.do?topicid=<%=topic_id %>">delete</a></td>
							</logic:present>
						</tr>
					</logic:iterate>
					<% 
						boolean have=false;
						if(current_offset!=0) {
							out.write("<tr><td colspan=\"6\" align=\"right\"><a href=\"/se3/firstPage.do?from=main\">首页</a> ");
							out.write("<a href=\"/se3/previewPage.do?from=main\">上一页</a> ");
							have=true;
						}
						if(current_end<list_size) {
							if(!have) {
								out.write("<tr><td colspan=\"6\" align=\"right\">");
							}
							out.write("<a href=\"/se3/nextPage.do?from=main\">下一页</a> ");	
							out.write("<a href=\"/se3/lastPage.do?from=main&size="+list_size+"\">末页</a></td></tr>");	
						}
						else {
							out.write("</td></tr>");
						}
					%>
				</table>
				<logic:present name="userid" scope="session">
					<logic:notPresent name="ban" scope="session">
						<p>
							<html:form action="/main">
								title : <html:text property="name" size="70"/><html:errors property="name"/><br/>
								group : <html:select property="group">
									<html:options collection="groups" property="name" labelProperty="name"/>
								</html:select><html:errors property="group"/><br/>
								post content : <html:textarea property="content" cols="80" rows="6"/><html:errors property="content"/><br/>
								<html:submit/>
							</html:form>
						</p>
					</logic:notPresent>
				</logic:present>
			</div>
			
			<div class="sidebar2">
				<logic:present name="userid" scope="session">
					<h4><html:link action="personalInformation"><bean:write name="name" scope="request"/></html:link></h4>
					<h4><bean:write name="grade" scope="request"/></h4>
					<logic:notPresent name="ban" scope="session">
						<logic:present name="new_letter" scope="request">
							<h4>
								You have got <br>
								<html:link action="viewTo"><bean:write name="new_letter" scope="request"/></html:link><br>
								 new letter<logic:notMatch name="new_letter" scope="request" value="1">s</logic:notMatch>.
							</h4>
						</logic:present>
					</logic:notPresent>
				</logic:present>
				<ul class="nav">
					<logic:present name="userid" scope="session">
						<li><html:link action="personalInformation">personal information</html:link></li>
						<logic:notPresent name="ban" scope="session">
							<li><html:link page="/center.jsp">add personal information</html:link></li>
							<li><html:link page="/view_letter.jsp">letter center</html:link></li>
						</logic:notPresent>
						<logic:present name="admin" scope="session">
							<li><html:link action="viewReport">view reports</html:link></li>
							<li><html:link action="banPre">ban user</html:link></li>
							<li><html:link action="encyclopedia">organize the encyclopedia</html:link></li>
						</logic:present>
						<li><html:link action="logout">logout</html:link></li>
					</logic:present>
					<logic:notPresent name="userid" scope="session">
						<li><html:link page="/form/login.jsp">login</html:link></li>
						<li><html:link page="/form/register.jsp">register</html:link></li>
					</logic:notPresent>
				</ul>
			</div>
			
            <div class="footer">
				<p>copyright@yssz</p>
			</div>
		</div>
	</body>
</html>